
if (!(/msie [6|7|8|9]/i.test(navigator.userAgent))) {
    new WOW().init();
}

var wow = new WOW({
    live: true,
    mobile: false
});

function setRemFontSize () {
    let designRadio = 1920 / 100
    // 所以为了方便计算，我们通常设置根元素font-size:100px;
    // 设计稿宽为1920，那么1rem就是19.2
    if(window.innerWidth <= 750){
        designRadio = 750 / 100
    }
    const remSize = window.innerWidth / designRadio
    console.log(window.innerWidth)
    console.log(remSize, 'remsize')
    document.querySelector('html').style.fontSize = remSize + 'px';
}
setRemFontSize()

window.addEventListener('resize', function () {
    setTimeout(function () {
        setRemFontSize();
    }, 200);
});

// 动态创建标签
$(function () {
    // 动态创建标签有跨域问题，所以需要部署之后改成绝对路径 https//xxx 本地测试用跨域浏览器解决此问题
    $('.wrapper').prepend($('<div>').load('./components/header.html', function () {
        // 加载完成之后再去mock hover 
        $('#headerlist').mouseenter(function () {
            $('.expand-box').css({opacity:1, 'z-index': 999, height:'2.4rem'})
        })
        if (window.innerWidth > 750) {
            $('.expand-box').mouseleave(function () {
                $('.expand-box').css({opacity:0, 'z-index': -1, height: 0})
                setNav()
            })
        }

        $('#headerlist li').mouseenter(function () {
            const idx = $(this).index()
            $('#headerlist li span').css({opacity: 0})
            $(this).find('span').css({opacity: 1})
            $(`.ep-ul li`).css({opacity: 0})
            $(`.ep-ul li:eq(${idx})`).css({opacity:1})
        })
        setNav()

        // 移动端点击出现nav
        $('#m-more').click(function () {
            $('.expand-box').css({opacity:1, 'z-index': 999, height:'3rem'})
            $('.m-mask').css({'display': 'block'})
        })
        $('.m-mask').click(function () {
            $(this).css({'display': 'none'})
            $('.expand-box').css({opacity:0, 'z-index': -1, height:'0'})
        })
    }))
    $('.wrapper').append($('<div>').load('./components/footer.html'))
    // setTimeout(() => {
    // }, 10)

    // 分页器加载
    $('.paging').load('./components/pagination.html')


    function setNav() {
        $('#headerlist li span').css({opacity: 0})
        // 根据路径匹配当前页面nav
        const location = window.location.href
        const pages = ['index', 'about', 'college', 'news', 'qa', 'contact']
        pages.map(function(v, i) {
            if (location.includes(v)){
                console.log(v, 999)
                $(`#headerlist li span:eq(${i})`).css({opacity: 1})
            }
        })
    }
});